import { Body, Controller, Post, Req, UsePipes, ValidationPipe } from '@nestjs/common';
import exceptionFactory from 'src/pip/exceptionFactory';
import { errorReturn, successReturn } from 'src/util';
import UserInfoDto from './dto/UserInfo.dto';
import { UserService } from './user.service';

@Controller('user')
export class UserController {
    constructor(
        private userService:UserService
    ) {}

    @Post('updateInfo')
    @UsePipes(new ValidationPipe({stopAtFirstError : true, whitelist : true, transform : true, exceptionFactory : exceptionFactory}))
    async updateUserInfo(@Body() params:UserInfoDto, @Req() { userId }) {
        try {
            let result = await this.userService.updateUserInfo(userId, params)
            if(result) return successReturn()
        } catch (error) {
            
        }

        return errorReturn()
    }
}
